Part Number Hot Search : 
USB20811 4809BF 13442 SR120 NV45AA BSP296N 0TRPB C3622
Product Description
Full Text Search
 

To Download AN2979 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  february 2010 doc id 15651 rev 1 1/12 AN2979 application note implementing a simple adc using the stm8l101xx comparator introduction this application note gives a simple method for implementing an a/d converter with a minimum amount of external components: one resistor and one capacitor. the pratical application example described in this document uses the stm8l101xx microcontroller comparator. www.st.com
contents AN2979 2/12 doc id 15651 rev 1 contents 1 application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 comparator features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 adc implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1 application flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3 hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4 measurements and calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.1 typical measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.2 precision of the measured value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.3 how to get a better accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.3.1 hardware solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.3.2 software solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
AN2979 application description doc id 15651 rev 1 3/12 1 application description 1.1 comparator features the stm8l101xx microcontroller embeds two zero-crossing comparators sharing the same current bias and the same voltage reference. this voltage reference can be: internal (comparison to ground) or external (comparison to a reference pin voltage) each comparator is connected to 4 channels which can be used to generate an interrupt, a timer input capture or a timer break. their polarity can be inverted. note: for external comparison be aware that the stm8l101xx comparator maximum input value is v dd -1.25 v with v ddmax = 3.6 v 1.2 adc implementation each comparator can be used to implement an adc. this technique is based on a simple principle: the signal to be measured is connected to the non-inverted input and the reference signal is an external signal connected to the inverting input. in the demonstration software, the comparator used is comp2 and the channel used as the signal to be measured is the channel 3 (pin pd2). the reference signal is generated by charging a capacitor through a resistor. while the voltage across the capacitor is being charged, it follows an exponential curve. this exponential equation has been implemented in the software. the time taken by the capacitor voltage to rise above the voltage value to be converted is used in the charge equation to retrieve the digital conversion value. charge equation: where: vmeas is the value to be mesaured v dd is the input voltage t is the time measured by timer2 when the comparator detects that the input voltage is above the reference voltage t is the rc constant (here r=10 k and c=100 nf so t= 1 ms) the capacitor is charged and discharged using the timer 2 pwm on channel1/ pb0. a timer is programmed to generate a 2 ms pwm with a duty cycle of 0.25. this 2-ms period permits an adc implementation using the full voltage range that the comparator tolerates. the capacitor charging curve is shown in the following figure. v meas v dd 1 t t --- ? ?? ?? exp ? ?? ?? =
application description AN2979 4/12 doc id 15651 rev 1 figure 1. capacitor charging curve the figure below shows the connection of the comparator to the required external components. figure 2. comparator connections 1. condition: v dd =3.3 v, r=10 k , c=100 nf note: when using the stm8l101-eval evaluation board you need to connect the pb0 pin to the pc4 pin. this way you use the resistor and capacitor already present on the board (no hardware needed). pin pc4 is configured as input floating to avoid any conflict. pwm output capacitor charging curve v dd t(ms) 3.3 2.5 2 1.5 1 0.5 123456789 (v) 3 ai - + c=100 nf pb0/pc4 pa6 pd2 comp_out r=10 k 7
AN2979 software description doc id 15651 rev 1 5/12 2 software description the software provided with this application note describes a way of implementing an a/d converter (using a timer and analog comparator interrupts). the application uses four peripherals: clk: the clock enables and provides the correct clock frequency for the peripherals. comp: the comparator detects when the input voltage is above the reference voltage tim2: timer 2 provides th e 2 ms pwm with a duty cycle of 0.25 generating the capacitor charge and discharge. timer 2 capture/compare interrupt routine handles the conversion. gpio: the general purpose i/o handles the i/o used. spi: used to communicate with the lcd. a generic file param.h contains the parameter values that can be modified in order to re-use the application and adapt it easily to other conditions. at the start, the lcd displays ?stm8l adc using comp?. then it continously displays the measured values. figure 3. application architecture & description note: the software can be compile d with cosmic and raisonance co mpilers. it contains projects for stvd and raisonance ide. a calibration of some parameters can be op tionally set if ?#define calibration? is uncommented in the param.h file. param.h param.c a i15 3 72 m a in.c s tm 8 l10x.h s tm 8 l10x.h s tm 8 l10x.h s tm 8 l10x.h s tm 8 l10x tim s tm 8 l10x comp s tm 8 l10x tim s tm 8 l10x.comp s tm 8 l10x cl s tm 8 l10x a pi s tm 8 l10x cl s tm 8 l10x a pi application layer api layer standard peripheral drivers s tm 8 l101x microcontroller
software description AN2979 6/12 doc id 15651 rev 1 2.1 application flowcharts figure 4. main loop flowchart figure 5. get conversion value flowchart a i15766 config u re the s y s tem clock to provide a m as ter clock fre qu ency f ma s ter = 16 mhz en ab le tim2 peripher a l clock config u re pc4 as inp u t flo a ting config u re pb0 as o u tp u t p us h p u ll for the pwm comp a r a tor config u r a tion en ab le comp a r a tor interf a ce config u re comp2 ch a nnel 3 with extern a l reference a nd pol a rity high connect comp2 o u tp u t to the tim2 inp u t c a pt u re1 tim config u r a tion tim2 to gener a te the pwm en ab le tim2 c a pt u re / comp a re interr u pt en ab le en ab le gener a l interr u pt s s pi config u r a tion di s pl a y on lcd config u re comp2 ch a nnel4 comp a re to the reference v a l u e en ab le tim2 di s pl a y on lcd s t a rt clock config u r a tion gpio config u r a tion a/d converter initi a liz a tion lcd config u r a tion c a li b r a tion option a l s t a rt a/d conver s ion end a i15767 get timer v a l u e get the conver s ion v a l u e cle a r tim2 pending b it di s pl a y on the lcd s t a rt end v in > v ref
AN2979 hardware description doc id 15651 rev 1 7/12 3 hardware description figure 6. circuit diagram stm8l101 evaluation board settings: remove jumper jp2 to connect an external input voltage instead of the potentiometer input. with the potentiometer rv1, the value is limited to 0.8 v and the signal is noisy (due to the lcd). so the display on the lcd screen would not be stable. connect the external adc voltage input directly to pd2. ground together the evaluation b oard and the external adc signal. an accurate 3.3 v mcu voltage can be tuned on the evaluation board using rv4. ai (comp2_ch3) pa 6 (comp_ref) r=10 k c=100 nf stm8l10x pb0 pc4 vss pd2 vdd !$#input
measurements and calibration AN2979 8/12 doc id 15651 rev 1 4 measurements and calibration 4.1 typical measurements the following values are given for information only. 4.2 precision of the measured value when using the rc charge equation, the precision of the measured value depends on the accuracy of the capacitor c and the resistor r. accuracy example: if c=100 nf with 10% accuracy: c acc1 =90 nf or c acc2 =110 nf if r=10 k with 2% accuracy: r acc1 =9.8 k or r acc2 =10.2 k calculation of the rc constant : charge equations: table 1. measured value after conversion and margin error for v dd =3.3 v value to be measured (v) measured value after conversion (v) error (%) 0.25 0.204 18.4% 0.5 0.419 16.2% 0.8 0.704 12% 1 0.903 9.7% 1.25 1.14 8.8% 1.5 1.39 7.33% 1.75 1.628 6.97% trc 10 10 3 () 100 10 9 ? () 1 ms == = t acc1 r acc1 c acc1 9.8 10 3 () 90 10 9 ? () 882 s == = t acc2 r acc2 c acc2 10.2 10 3 () 110 10 9 ? () 1.122 ms == = v meas v dd 1 t t --- ? ?? ?? exp ? ?? ?? = v measacc1 v dd 1 t t acc1 ----------------- ? ?? ?? ?? exp ? ?? ?? ?? = v measacc2 v dd 1 t t acc2 ----------------- ? ?? ?? ?? exp ? ?? ?? ?? =
AN2979 measurements and calibration doc id 15651 rev 1 9/12 the following figure shows the impact of the capacitor and resistor accuracy. figure 7. charge equation depending on rc accuracy 1. in blue: v measacc1 ---- in red: v meas ---- in green: v measacc2 2. condition: v dd =3.3 v note: the results are not only impacted by the marging error due to hardware components but also by the accuracy of the mcu clock. in this example, the device works at a hsi frequency of 16 mhz at 25 c, that is, with a clock accuracy of 1% (refer to the datasheet). the temperature variation also impacts the accuracy of the measured value as the microcontroller, resistors and capacitors are temperature dependent. 4.3 how to get a better accuracy 4.3.1 hardware solution the first solution is to choose components with a high accuracy value (this may imply a higher cost). 4.3.2 software solution the second solution is to calibrate the rc constant in the software using v dd as a reference. implementation description in order to perform the calibration, you need to uncomment the ?#define calibration? in the ?param.h? file. y = 3.3(1-exp(-x/0.882)) y = 3.3(1-exp(-x)) y = 3.3(1-exp(-x/1.122)) 0.5 1 1.5 2 2.5 3 0.5 1 1.5 2 2.5 v ms vmeas_max = 2.05 tmax tacc1max tacc2max tacc2max = 1.09 ms tacc1max = 0.856ms tmax = 0.970ms
measurements and calibration AN2979 10/12 doc id 15651 rev 1 the calibration is then performed by firware and the rc constant is updated. this constant is used in the charge equation. on the stm8l101-eval evaluation board, the comp2 channel 4 (pd3) is connected to v dd via a resistor bridge. figure 8. evaluation board calibration schematic as v dd =3.3 v, pd3 is a fixed value equal to 0.4 v in the file ?param.h? you need to define the ?expected_value? equal to 0.4 ( this value needs to be updated if a different resistor bridge is used). the specific function ?calibration()? configures the comp2 channel 4 and compares the value measured on this channel with the expect ed value. this function then updates the rc constant that will be used afterwards. when the calibration is performed, the comp2 configuration changes to use the channel 3 (pd2). the following table lists a few measurement examples with a calibration performed at v dd =3.3 v, r=10 k and c=100 nf. table 2. accuracy measurement when the calibration is performed value to be measured (v) measured value after conversion (v) error (%) 0.25 0.233 6.8% 0.5 0.475 5% 0.8 0.792 1.25% 10.991% 1.2 1.211 0.92% 1.5 1.512 0.8% 1.75 1.784 1.9% ai k 7 k 7 2k 7 #     n & #alibrationinput !$#input 0$#/-0?#( 0$#/-0?#( 34-,x 6 $$ 0# 0" 0! #/-0?2%& 633
AN2979 revision history doc id 15651 rev 1 11/12 5 revision history table 3. document revision history date revision changes 12-feb-2010 1 intitial release.
AN2979 12/12 doc id 15651 rev 1 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a parti cular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. unless expressly approved in writing by an authorized st representative, st products are not recommended, authorized or warranted for use in milita ry, air craft, space, life saving, or life sustaining applications, nor in products or systems where failure or malfunction may result in personal injury, death, or severe property or environmental damage. st products which are not specified as "automotive grade" may only be used in automotive applications at user?s own risk. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2010 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN2979

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X